#!/usr/bin/python3
# coding=utf-8

class UnifyBookCatalog:

    def __init__(self) -> None:
        super().__init__()
        self.id = None
        self.title = None
        self.gmtCreate = None
        self.gmtModified = None
        self.refUrl = None
        self.bookId = None
        self.isDownload = None
    def getIsDownload(self):
        return self.isDownload

    def setIsDownload(self, isDownload):
        self.isDownload = isDownload

    def getId(self):
        return self.id

    def setId(self, id):
        self.id = id

    def getTitle(self):
        return self.title

    def setTitle(self, title):
        self.title = title

    def getGmtCreate(self):
        return self.gmtCreate

    def setGmtCreate(self, gmtCreate):
        self.gmtCreate = gmtCreate

    def getGmtModified(self):
        return self.gmtModified

    def setGmtModified(self, gmtModified):
        self.gmtModified = gmtModified

    def getRefUrl(self):
        return self.refUrl

    def setRefUrl(self, refUrl):
        self.refUrl = refUrl

    def getBookId(self):
        return self.bookId

    def setBookId(self, bookId):
        self.bookId = bookId

    def getSaveSql(self):
        try:
            saveSql = "INSERT INTO unify_book_catalog(book_id, title, gmt_create, ref_url) " \
                      "VALUES ('%s','%s','%s','%s')" % \
                (self.bookId, self.title, self.gmtCreate, self.refUrl)
            return saveSql
        except BaseException as e:
            print(e)
            return

    '''
    更新记录的下载状态
    '''
    def getUpdateIsDownLoadSql(self, id):
        try:
            updateSql = "update unify_book_catalog set is_download = '%d' where id = '%s'" % (1, id)
            return updateSql
        except BaseException as e:
            print(e)
            return

    '''
    查询未下载的记录列表
    '''
    def getUndownloadSql(self, bookId):
        querySql = "SELECT * from unify_book_catalog where book_id = '%s' and is_download = '%d'" % (bookId, 0)
        return querySql

    '''
    查询最新一条章节信息
    '''
    def getRecentlyInfoByBookId(self, bookId):
        querySql = "SELECT title from unify_book_catalog where book_id = '%s' order by id desc limit 1" % (bookId)
        return querySql